package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CResetPwd
import com.onlyphoto.onlymall.mvp.model.MResetPwdImpl
import com.onlyphoto.onlymall.base.BasePresenter


class PResetPwdImpl(mContext: Context, mView: CResetPwd.IVResetPwd) : BasePresenter<CResetPwd.IVResetPwd, MResetPwdImpl>(mContext, mView, MResetPwdImpl()), CResetPwd.IPResetPwd {
    override fun getVerify(getType: Int, phone: String) {
        mModel.getVerify(getType, phone, object : BaseObserver<Void>(mContext.get()){
            override fun onSuccess(data: Void?, msg: String?) {
                mView.getVerifySuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<Void>?) {
                if (t?.error_code == 1 || t?.error_code == 2) {
                    mView.showMsg(t.msg!!)
                } else {
                    mView.getVerifyFail()
                }
            }

            override fun onFailure(e: Throwable?) {
                mView.getVerifyFail()
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }

    override fun resetPwd() {
        val bean = mView.getResetPwdBean()
        mModel.resetPwd(bean, object :BaseObserver<Void>(mContext.get()){
            override fun onSuccess(data: Void?, msg: String?) {
                mView.resetPwdSuccess()
            }

            override fun onCodeError(t: BaseNetworkResponse<Void>?) {
                if (t?.error_code == 1 || t?.error_code == 2) {
                    mView.showMsg(t.msg!!)
                } else {
                    mView.showMsg("网络错误，请稍后重试")
                }
            }

            override fun onFailure(e: Throwable?) {
                mView.showMsg("网络错误，请稍后重试")
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
